﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using com.loto.Common.DBUtility;

namespace com.huigo.Framework.BLL
{
    public class LoginLog
    {
        /// <summary>
        /// 添加登录日志
        /// </summary>
        /// <param name="type"></param>
        /// <param name="custFid"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        public static int InsertLoginLog(byte type, long custFid, string ip)
        {
            Model.LoginLog loginLog = new com.huigo.Framework.Model.LoginLog();
            loginLog.LogType = type;
            loginLog.LogCreatedBy = custFid;
            loginLog.LogCreatedOn = DateTime.Now;
            loginLog.LogIp = ip;
            return Convert.ToInt32(SqlServerDal.LoginLog.Insert(loginLog, null));
        }
        /// <summary>
        /// 查询用户登录日志
        /// </summary>
        /// <param name="createBy"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static List<Model.LoginLog> GetLoginLog(long createBy, byte type)
        {
            List<string> fileds = new List<string>()
            {
                "LOG_ID",
                "LOG_TYPE",
                "LOG_CREATED_BY",
                "LOG_CREATED_ON",
                "LOG_IP"
            };
            List<WhereStatement> whereList = new List<WhereStatement>()
            {
                new WhereStatement("LOG_TYPE","=",""+type+"","and"),
                new WhereStatement("LOG_CREATED_BY","=",""+createBy+"","")
            };
            List<OrderByStatement> orderList = new List<OrderByStatement>()
            {
                new OrderByStatement("LOG_CREATED_ON ",false)
            };
            return SqlServerDal.LoginLog.GetItems(fileds, null, whereList, orderList, null, null);
        }
    }
}
